﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace ShoppingList.DTO
{
    public class Entity:INotifyPropertyChanged
    {
        protected internal int id;

        public bool IsNew { get { return id == 0; } }

        public int Id
        {
            get { return id; }
            set
            {
                id = value;
                OnPropertyChanged("Id");
            }
        }


        #region INotifyPropertyChanged Members

        public virtual void OnPropertyChanged(string propertyName)
        {
//            if (EntityState == EntityState.Unchanged) EntityState = EntityState.Modified;
            if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        public override int GetHashCode()
        {
            return id;
        }

        public override bool Equals(object obj)
        {
            Entity e = obj as Entity;
            return (e.id == id && e.GetType() == GetType());
        }

    }
}
